package me.sunpeng.design.singleton.type4;

/**
 * @author sp
 */
public class SingletonTest04 {
    public static void main(String[] args) {

    }

}

class Singleton {
    private static Singleton instance;

    private Singleton() {

    }

    //提供一个静态的共有方法，加入同步处理的代码，解决线程安全问题
    //即懒汉式
    public static synchronized Singleton getInstance() {
        if (instance == null) {
            return new Singleton();
        }
        return instance;
    }
}